package com.wc.AlgoOJ_homework.AlgoOJ_test3.H_排兵布阵;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/11 21:48
 * @description http://43.138.190.70:8888/p/988?tid=65e5dab127489dab814f76e2
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[][] a = new int[N][4];
    static boolean[] vis = new boolean[N];
    static int t, n, m;
    static Set<Long> set = new HashSet<>();

    public static void main(String[] args) {
        t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            boolean flg = true;
            for (int i = 1; i <= m; i++) {
                int idx = sc.nextInt();
                if (a[idx][2] != 0) flg = false;
                a[idx][2] = sc.nextInt();
                a[idx][3] = sc.nextInt();
            }

            if (flg) {
                for (int i = 1; i <= m; i++) {
                    if (!vis[i] && a[i][2] != 0) {
                        set.clear();
                        vis[i] = true;
                        long res = deploy(a[i][2]);
                        if (res == Long.MIN_VALUE) {
                            out.println("NO");
                            flg = false;
                            break;
                        }
                    }
                }
            } else {
                out.println("NO");
            }
            if (flg) out.println("YES");
            for (int i = 1; i <= n; i++) Arrays.fill(a[i], 0);
            Arrays.fill(vis, false);
        }
        out.flush();
    }

    // 表示 x 依赖 y
    static long deploy(int y) {
        if (a[y][2] == 0) {
            set.add(0L);
            return 0;
        }
        if (vis[y]) return Long.MIN_VALUE;
        vis[y] = true;
        long res = deploy(a[y][2]);
        if (res == Long.MIN_VALUE) return Long.MIN_VALUE;
        res = a[y][3] + res;
        if (set.contains(res)) return Long.MIN_VALUE;
        set.add(res);
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
